package com.hitqz.robot.driver.zmq.protocol.handler;

import com.example.tutorial.AddressBookProtos;
import com.google.protobuf.ProtocolStringList;
import com.hitqz.robot.driver.util.WheelCacheUtil;
import com.hitqz.robot.driver.util.WheelToolkit;
import lombok.extern.slf4j.Slf4j;
import navconnector.NavconnectorBase;
import org.springframework.stereotype.Component;

import java.util.concurrent.locks.Lock;

/**
 * StringArray数据类型处理类
 *
 * @author wengyx
 * @date 2021-09-14 16:47
 **/
@Slf4j
@Component
public class StringArrayHandler implements HandlerZMQService {


    @Override
    public void handlerMsg(String robotSn, byte[] data) throws Exception {
        AddressBookProtos.StringArray stringArray = AddressBookProtos.StringArray.parseFrom(data);
        String type = stringArray.getDescriptorForType().getName();
        int ackId = stringArray.getHeader().getAck();
        int objId = stringArray.getHeader().getObj();
        ProtocolStringList dataList = stringArray.getDataList();
        switch (objId) {
            //返回2D地图名称
            case AddressBookProtos.StringArray.OBJ_ID.GET_MAP_2D_NAME_REP_VALUE->{
                WheelCacheUtil.put(WheelCacheUtil.KEY_MAP_2D_NAMES,dataList);
            }
            //返回3D地图名称
            case AddressBookProtos.StringArray.OBJ_ID.GET_MAP_3D_NAME_REP_VALUE->{
                WheelCacheUtil.put(WheelCacheUtil.KEY_MAP_3D_NAMES,dataList);
            }
            //返回PB地图名称
            case AddressBookProtos.StringArray.OBJ_ID.GET_MAP_PB_NAME_REP_VALUE->{
                WheelCacheUtil.put(WheelCacheUtil.KEY_MAP_PB_NAMES,dataList);
            }
            //返回mp3文件名称
            case AddressBookProtos.StringArray.OBJ_ID.GET_MP3_NAME_REP_VALUE->{
                WheelCacheUtil.put(WheelCacheUtil.KEY_MP3_NAMES,dataList);
            }
        }
        //释放锁
        WheelToolkit.release(ackId,type, objId, true);

    }

}
